package com.fqy.thread03.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * User: fqy
 * Date: 2021/9/4
 * Time: 18:27
 * Describe: 线程池 模拟20个客户来银行办理业务
 */
public class PoolInitDemo {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(5); //一池5线程
        ExecutorService threadPool1 = Executors.newSingleThreadExecutor();    //一池1线程
        ExecutorService threadPool2 = Executors.newCachedThreadPool();        //一池n线程
        try {
            for (int i = 0; i < 20; i++) {
                int finalI = i + 1;
                threadPool2.submit(() -> {
                    System.out.println("业务员" + Thread.currentThread().getName() + "\t 正在给第" + finalI + "个客户办理业务！");
                });
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            threadPool.shutdown();
        }

    }
}